#!/usr/bin/python

import os

separate_raw = True
seperate_avi = True
compress_avi = True
create_thumbs = True

raw_dst = './raw'
avi_dst = './video'

def make(cmd):
    print cmd
    os.system(cmd)

if separate_raw:
    try:
	if len(filter(lambda x:x.lower().endswith(".cr2"), os.listdir("."))) > 0:
	    os.mkdir(raw_dst)
    except OSError:
	pass

    print 'moving raw files to raw dir [%s]'%raw_dst
    make('mv *.cr2 *.CR2 %s'%raw_dst)

if seperate_avi:
    try:
	if len(filter(lambda s:s.lower().endswith('.avi'), os.listdir('.'))) > 0:
	    os.mkdir(avi_dst)
	    print 'moving video files to video dir [%s]'%avi_dst
	    make('mv *.avi *.AVI %s'%avi_dst)

	    if commpress_avi:
		import compress_avi as c_avi
		c_avi.compress_dir(avi_dst)
    except OSError:
	pass


print 'rotating all jpeg images'
make('exiftran -api *.jpg *.JPG')

if create_thumbs:
    import create_img_thumbs
    create_img_thumbs.create_thumbs(".", False)
    make("mkdir thumb")
    make("mv thumb_* thumb")
    make("eog thumb")
